version 14.0
log using "\Users\sgolder\Dropbox\Portfolio Allocation\replication\warwickdruckman.log", replace
set more off
#delimit ;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      warwick_druckman_data.do                        *;
*       Date:           August 16, 2016                                 *;
*       Author:         Molly Ariotti and Sona Golder                   *;
*       Purpose:      	Take original Warwick and Druckman (2006) data  *;
*                       and put it in more useful format.               *;
* 	    Input File:     wtportfolios5.dta                               *;
*       Output File:    warwickdruckman.log                             *;
*       Data Output:    Europe.dta                                      *;             
*       Previous file:  none                                            *;
*       Machine:        laptop                           				*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*       Open and summarize dataset.                                     *;
*     ****************************************************************  *;

use "C:\Users\sgolder\Dropbox\Portfolio Allocation\replication\wtportfolios5.dta";


sum;

*     ****************************************************************  *;
*      Sort on case number, add country names, rename some variables    *;
*      Note that Germany = 16 not a typo (was listed as West Germany)   *;
*      Create some variables                                            *;
*     ****************************************************************  *;

sort caseno;

gen str18 countryname=".";
replace countryname = "Austria" if country==1;
replace countryname = "Belgium" if country==2;
replace countryname = "Denmark" if country==3;
replace countryname = "Finland" if country==4;
replace countryname = "France" if country==5;
replace countryname = "Germany" if country==16; 
replace countryname = "Iceland" if country==6; 
replace countryname = "Ireland" if country==7; 
replace countryname = "Italy" if country==8; 
replace countryname = "Luxembourg" if country==9; 
replace countryname = "Netherlands" if country==10; 
replace countryname = "Norway" if country==11; 
replace countryname = "Portugal" if country==12; 
replace countryname = "Sweden" if country==14;

gen countrycode = . ;
replace countrycode = 1 if country==1;
replace countrycode = 2 if country==2;
replace countrycode = 3 if country==3;
replace countrycode = 4 if country==4;
replace countrycode = 5 if country==5;
replace countrycode = 6 if country==16;
replace countrycode = 7 if country==6; 
replace countrycode = 8 if country==7; 
replace countrycode = 9 if country==8; 
replace countrycode = 10 if country==9; 
replace countrycode = 11 if country==10; 
replace countrycode = 12 if country==11; 
replace countrycode = 13 if country==12; 
replace countrycode = 14 if country==14;

drop portpr1 portpr2 ;
egen portfolios = rowtotal(port*) ;

rename ppunwtd portfolioshare;
rename ptyprop seatshare;
rename form formateur;
rename df1 year;
rename cabsize government_portfolios ;
rename seats party_seats ;

sort countrycode caseno;
egen cabinetcode = group(caseno) ;

keep portfolios portfolioshare seatshare formateur year countryname countrycode party party_seats government_portfolios cabinetcode;
gen region = 2;
gen cowcode = . ;
  replace cowcode = 305 if countrycode == 1;
  replace cowcode = 211 if countrycode == 2;
  replace cowcode = 390 if countrycode == 3;
  replace cowcode = 375 if countrycode == 4;
  replace cowcode = 220 if countrycode == 5;
  replace cowcode = 255 if countrycode == 6;
  replace cowcode = 395 if countrycode == 7;
  replace cowcode = 205 if countrycode == 8;
  replace cowcode = 325 if countrycode == 9;
  replace cowcode = 212 if countrycode == 10;
  replace cowcode = 210 if countrycode == 11;
  replace cowcode = 385 if countrycode == 12;
  replace cowcode = 235 if countrycode == 13;
  replace cowcode = 380 if countrycode == 14;



egen government_seats = total(party_seats), by(cabinetcode) ;

gen code = (region*100000) + (countrycode*1000) + cabinetcode ;
gen presidential = 0 ;

label var countryname "country name";
label var countrycode "country code";
label var region "1=Africa, 2=Western Europe, 3=Latin America";
label var party_seats "number of legislative seats per party";
label var party "party number or acronym";
label var cabinetcode "cabinet code";
label var code "region, country code, cabinet code";
label var cowcode "cow code";
label var portfolios "number of portfolios per party";
label var formateur "1 = formateur, 0 = otherwise";
label var presidential "1 = presidential, 0 = parliamentary"; 
label var government_portfolios "number of portfolios in the government";
label var government_seats "number of seats controlled by government";
label var seatshare "party share of leg seats controlled by govt";
label var portfolioshare "party share of govt portfolios";
label var year "year in which government begins";


save "C:\Users\sgolder\Dropbox\Portfolio Allocation\replication\Europe.dta", replace;

*     ****************************************************************  *;
*       How large are European cabinets?                                *;
*     ****************************************************************  *;

collapse (mean) government_portfolios, by(cabinetcode);

sum government_portfolios;

log close;
exit;
